<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Transfer - Decorators</title>
<link rel="stylesheet" type="text/css" href="default.css" />
</head>
<body>
<a href="index.html" id="nav">Home</a>
<h1>Using Decorators</h1>
<p>
	A 'decorator' is used when you wish to write your own CFC to be used to represent data, in place of the Transfer generated Object.  
</p>
<p>
	An example of this being to write a User.cfc to represent a User record within a database.
</p>
<p>
	The 'decorator' that has been written wraps around the TransferObject that is generated by Transfer and 
	automagically extends any public method generated on the decorated TransferObject.
</p>
<h2>Authoring a decorator</h2>
<p>
	Decorators are set using the 'decorator' attribute on the 'object' element in the
	<a href="transfer.doc.html">configuration file</a>
</p>
<p>
	Decorators must extend <a href="cfcdoc/contentfb32.html">transfer.com.TransferDecorator</a>
</p>
<h2>Overwriting methods</h2>
<p>
	If a method exists in the Decorator, it will overwrite the method of the generated TransferObject's method.  
</p>
<p>
	Overwriting <a href="cfcdoc/contentfb32.html#configure()">configure()</a> will be run when the 
	object is first created.
</p>
<p>
	If you wish to have access to the TransferObject stored within the decorator, and any of its
	original generated methods, you can use <a href="cfcdoc/contentfb32.html#getTransferObject()">getTransferObject()</a>
	to return the original TransferObject
</p>
<p>
	An example of an overwritten method that utilises these methods, is if a User TransferObject has a 'setHomePageURL()' method generated,
	that you wanted to ensure had 'http://' at the beginning, you could put in your User.cfc decorator
	<br/>
<pre>
	&lt;cffunction name="setHomePageURL" access="public" returntype="void" output="false"&gt;
		&lt;cfargument name="url" type="string" required="Yes"&gt;
		&lt;cfif findNoCase("http://", arguments.url)&gt;
			&lt;cfset arguments.url = "http://" &amp; arguments.url&gt;
		&lt;/cfif&gt;
		&lt;cfset getTransferObject().setHomePageURL(arguments.url)&gt;
	&lt;/cffunction&gt;
</pre>

This overwrites the generated setHomePageURL() method, and extends its functionality.
</p>
<h2>Access to Transfer</h2>
<p>
	The method of <a href="cfcdoc/contentfb32.html#getTransfer()">getTransfer()</a> is available to the 
	Decorator CFC, and gives access to the <a href="cfcdoc/content3c54.html">transfer.com.Transfer</a> library.
</p>

</body>
</html>